package br.com.massai.model.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "PRIVILEGIO", schema = "PORTAL")
@SequenceGenerator(name = "seqPrivilegio", sequenceName = "seq_privilegio", allocationSize = 1)
public class Privilegio implements Serializable {

	private static final long serialVersionUID = -6749178745950158272L;

	@Id
	@Column(name = "ID_PRIVILEGIO")
	@GeneratedValue(generator = "seqPrivilegio", strategy = GenerationType.SEQUENCE)
	private Long id;

	@Column(name = "DESCRICAO", length = 255, nullable = false, columnDefinition = "VARCHAR(255)")
	private String descricao;

	@Column(name = "FUNCAO", nullable = false, length = 50, unique = true, columnDefinition = "VARCHAR(100)")
	private String funcao;
	
	@ManyToOne(optional = false)
	@JoinColumn(name = "ID_MODULO", referencedColumnName = "ID_MODULO")
	private Modulo modulo;
	
	@OneToMany(mappedBy = "privilegio", fetch = FetchType.LAZY)
	private List<Url> urls;

	@Transient
	private boolean selecionado;
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Privilegio)
			if(((Privilegio) obj).getFuncao().equals(getFuncao())) return true;
			else return false;
		else
			return false;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public String getFuncao() {
		return funcao;
	}

	public void setFuncao(String funcao) {
		this.funcao = funcao;
	}

	public Modulo getModulo() {
		return modulo;
	}

	public void setModulo(Modulo modulo) {
		this.modulo = modulo;
	}

	public boolean isSelecionado() {
		return selecionado;
	}

	public void setSelecionado(boolean selecionado) {
		this.selecionado = selecionado;
	}

	public List<Url> getUrls() {
		return urls;
	}

	public void setUrls(List<Url> urls) {
		this.urls = urls;
	}
}